<template>
  <div class="mall-pages">
    <el-card>
      <template #header>
        <div class="card-header">
          <span class="title">页面管理</span>
          <el-button type="primary" @click="$router.push('/mall/diy-designer')">
            <el-icon><Plus /></el-icon>
            新建页面
          </el-button>
        </div>
      </template>

      <el-table :data="pages" border>
        <el-table-column prop="name" label="页面名称" width="200" />
        <el-table-column prop="type" label="页面类型" width="120">
          <template #default="{ row }">
            <el-tag>{{ getPageTypeLabel(row.type) }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="path" label="访问路径" width="200" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="{ row }">
            <el-tag :type="row.status === 1 ? 'success' : 'warning'">
              {{ row.status === 1 ? '已发布' : '草稿' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="updateTime" label="更新时间" width="180" />
        <el-table-column label="操作" width="250" fixed="right">
          <template #default="{ row }">
            <el-button link type="primary" @click="handleEdit(row)">编辑</el-button>
            <el-button link type="success" @click="handlePreview(row)">预览</el-button>
            <el-button link type="info" @click="handleCopy(row)">复制</el-button>
            <el-button link type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRouter } from 'vue-router'
import { Plus } from '@element-plus/icons-vue'

const router = useRouter()

const pages = ref([
  {
    id: 1,
    name: '商城首页',
    type: 'home',
    path: '/pages/home',
    status: 1,
    updateTime: '2025-01-18 10:00:00'
  },
  {
    id: 2,
    name: '618活动页',
    type: 'activity',
    path: '/pages/618',
    status: 1,
    updateTime: '2025-01-17 15:30:00'
  },
  {
    id: 3,
    name: '新品发布',
    type: 'activity',
    path: '/pages/new-product',
    status: 0,
    updateTime: '2025-01-16 09:20:00'
  }
])

const getPageTypeLabel = (type) => {
  const map = {
    home: '首页',
    category: '分类页',
    activity: '活动页',
    custom: '自定义'
  }
  return map[type] || type
}

const handleEdit = (row) => {
  router.push({ path: '/mall/diy-designer', query: { id: row.id } })
}

const handlePreview = (row) => {
  ElMessage.info('预览功能开发中')
}

const handleCopy = (row) => {
  ElMessage.success(`已复制页面：${row.name}`)
}

const handleDelete = (row) => {
  ElMessageBox.confirm(`确定删除页面 "${row.name}"？`, '提示', {
    type: 'warning'
  }).then(() => {
    ElMessage.success('删除成功')
  })
}
</script>

<style scoped>
.mall-pages {
  padding: 20px;
  background: #f5f5f5;
  min-height: 100vh;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title {
  font-size: 18px;
  font-weight: bold;
}
</style>

